function ListNode(val, next) {
  this.val = (val === undefined ? 0 : val)
  this.next = (next === undefined ? null : next)
}

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
function createList(arr) {
  if (arr.length == 0)
    return null;
  let head = new ListNode(arr[0], null),
    headNode = head;
  for (let i = 1; i < arr.length; i++) {
    let temp = new ListNode(arr[i], null);
    head.next = temp;
    head = temp;
  }
  return headNode;
}

function showList(head) {
  while (head) {
    console.log(head.val);
    head = head.next;
  }
}
var getIntersectionNode = function(headA, headB) {
  let countA = 0, countB = 0, tempA = headA, tempB = headB;
  while(tempA) {
    countA++;
    tempA = tempA.next;
  }
  while(tempB) {
    countB++;
    tempB = tempB.next;
  }
  while(countA != countB) {
    if(countA > countB) {
      countA--;
      headA = headA.next;
    } else {
      countB--;
      headB = headB.next;
    }
  }
  while(headA != headB) {
    headA = headA.next;
    headB = headB.next;
  }
  return headA;
};
let listA = [4,1,8,4,5], listB = [5,6,1,8,4,5];
// intersectVal = 8, skipA = 2, skipB = 3;
console.log(oddEvenList(listA, listB));
listA = [1,9,1,2,4], listB = [3,2,4];
// intersectVal = 2, skipA = 3, skipB = 1
console.log(oddEvenList(listA, listB));
